#include"json.hpp"
using json = nlohmann::json;

#include<iostream>
#include<vector>
#include<map>
#include<string>

using namespace std;

//json test
string test1()
{
    json js;
    js["msg1"] = 2;
    js["from"] = "zhangsan";
    js["to"]  = "li si";

    string sendBuf = js.dump();
    cout<< sendBuf.c_str() <<endl;
    return sendBuf;
}

string test2()
{
    json js;  
    js["id"] = {1,2,3};
    js["msg"]["zhang san"] = "hello worold";

    return js.dump();
}

string test3()
{
    json js;
    // 直接序列化一个vector容器
    vector<int> vec;
    vec.push_back(1);
    vec.push_back(2);
    vec.push_back(5);
    js["list"] = vec;
    // 直接序列化一个map容器
    map<int, string> m;
    m.insert({1, "黄山"});
    m.insert({2, "华山"});
    m.insert({3, "泰山"});
    js["path"] = m;

    string sendBuf = js.dump(); //序列化成 json字符串
    cout<<js<<endl;
    return sendBuf;
}

int main()
{
    //test1();
    //test2();
    // string recvBuf = test1();
    // json jsbuf = json::parse(recvBuf);
    // cout<<jsbuf["msg1"]<<endl;
    // cout<<jsbuf["from"]<<endl;
    string recvBuf = test3();
    json jsbuf = json::parse(recvBuf);
    vector<int> vec = jsbuf["list"];
    cout<<vec[0]<<endl;
    return 0;
}
